package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.StockVirtualReport;
import com.sumi.erp.service.IStockVirtualReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 采购库存Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/erp/report")
public class StockVirtualReportController extends BaseController
{
    @Autowired
    private IStockVirtualReportService stockVirtualReportService;

    /**
     * 查询采购库存列表
     */
    @PreAuthorize("@ss.hasPermi('erp:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockVirtualReport stockVirtualReport)
    {
        startPage();
        List<StockVirtualReport> list = stockVirtualReportService.selectStockVirtualReportList(stockVirtualReport);
        return getDataTable(list);
    }

    /**
     * 导出采购库存列表
     */
    @PreAuthorize("@ss.hasPermi('erp:report:export')")
    @Log(title = "采购库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockVirtualReport stockVirtualReport)
    {
        List<StockVirtualReport> list = stockVirtualReportService.selectStockVirtualReportList(stockVirtualReport);
        ExcelUtil<StockVirtualReport> util = new ExcelUtil<StockVirtualReport>(StockVirtualReport.class);
        util.exportExcel(response, list, "采购库存数据");
    }

    /**
     * 获取采购库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stockVirtualReportService.selectStockVirtualReportById(id));
    }

    /**
     * 新增采购库存
     */
    @PreAuthorize("@ss.hasPermi('erp:report:add')")
    @Log(title = "采购库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockVirtualReport stockVirtualReport)
    {
        return toAjax(stockVirtualReportService.insertStockVirtualReport(stockVirtualReport));
    }

    /**
     * 修改采购库存
     */
    @PreAuthorize("@ss.hasPermi('erp:report:edit')")
    @Log(title = "采购库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockVirtualReport stockVirtualReport)
    {
        return toAjax(stockVirtualReportService.updateStockVirtualReport(stockVirtualReport));
    }

    /**
     * 删除采购库存
     */
    @PreAuthorize("@ss.hasPermi('erp:report:remove')")
    @Log(title = "采购库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stockVirtualReportService.deleteStockVirtualReportByIds(ids));
    }
}
